//
//  RentalDetailController.m
//  StarOrangeStaff
//
//  Created by lshenrong on 2020/6/30.
//  Copyright © 2020 lshenrong. All rights reserved.
//

#import "VehicleDetailController.h"
#import "InputTempletTwelveTableViewCell.h"


@interface VehicleDetailController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UILabel *titleLblFirst;
@property (nonatomic,strong) UILabel *titleLblSecond;
@property (nonatomic,strong) UILabel *deleteLbl;

@end

@implementation VehicleDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"车辆详情";
    self.navigationItem.rightBarButtonItem = [UIConfigure barButtonItemWithTitle:@"编辑" target:self action:@selector(editAction)];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.view);
    }];
    
    
}

#pragma mark - Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 2) {
        return 20.00f;
    }
    return 40.00f;

}

//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
   
    if (section == 0) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = kAppBackgoundColor;
        [view addSubview:self.titleLblFirst];
        [self.titleLblFirst mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view.mas_left).offset(15);
            make.centerY.equalTo(view.mas_centerY);
        }];
        return view;
    }else if (section == 1){
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = kAppBackgoundColor;
        [view addSubview:self.titleLblSecond];
        [self.titleLblSecond mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(view.mas_left).offset(15);
            make.centerY.equalTo(view.mas_centerY);
        }];
        return view;
    }else {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = kAppBackgoundColor;
        return view;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    InputTempletTwelveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"InputTempletTwelveTableViewCellIdentifier"];
    if (indexPath.section == 0) {
         if (indexPath.row == 0) {
               cell.placeholder = @" ";
               cell.cellTitle =  @"车牌号";
               cell.inputTextField.text = @"企业";
               @weakify(self)
               cell.textChangeBlock = ^(NSInteger tag, id body) {
                   @strongify(self)
                   
               };
           }else if (indexPath.row == 1) {
               cell.placeholder = @"";
               cell.cellTitle =  @"品牌";
               cell.inputTextField.text = @"粤A100AS";
               cell.inputTextField.keyboardType =  UIKeyboardTypeDefault;
               @weakify(self)
               cell.textChangeBlock = ^(NSInteger tag, id body) {
                   @strongify(self)
                   
               };
           }else if (indexPath.row == 2) {
               cell.placeholder = @" ";
               cell.cellTitle =  @"座位数";
               cell.inputTextField.text = @"5座";

               cell.inputTextField.keyboardType =  UIKeyboardTypeDefault;
               @weakify(self)
               cell.textChangeBlock = ^(NSInteger tag, id body) {
                   @strongify(self)
                   
               };
           }else if (indexPath.row == 3) {
               cell.placeholder = @" ";
               cell.cellTitle =  @"颜色";
               cell.inputTextField.text = @"白色";

               cell.inputTextField.keyboardType =  UIKeyboardTypeDefault;
               @weakify(self)
               cell.textChangeBlock = ^(NSInteger tag, id body) {
                   @strongify(self)
                   
               };
           }else if (indexPath.row == 4) {
               cell.placeholder = @" ";
               cell.cellTitle =  @"车龄";
               cell.inputTextField.text = @"2年";

               cell.inputTextField.keyboardType =  UIKeyboardTypeDefault;
               @weakify(self)
               cell.textChangeBlock = ^(NSInteger tag, id body) {
                   @strongify(self)
                   
               };
           }else if (indexPath.row == 5) {
               cell.placeholder = @" ";
               cell.cellTitle =  @"双牌照";
               cell.inputTextField.text = @"否";
               cell.inputTextField.delegate = self;
               cell.inputTextField.keyboardType =  UIKeyboardTypeDefault;
               @weakify(self)
               cell.textChangeBlock = ^(NSInteger tag, id body) {
                   @strongify(self)
                   
               };
           }
        
        return cell;
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
                     cell.placeholder = @" ";
                     cell.cellTitle =  @"司机名字";
                     cell.inputTextField.keyboardType =  UIKeyboardTypeDefault;
                     cell.inputTextField.text = @"雷子";

                     @weakify(self)
                     cell.textChangeBlock = ^(NSInteger tag, id body) {
                         @strongify(self)
                         
                     };
                 }else if (indexPath.row == 1) {
                     cell.placeholder = @" ";
                     cell.cellTitle =  @"联系方式";
                     cell.inputTextField.text = @"13265114489";

                     cell.inputTextField.keyboardType =  UIKeyboardTypeDefault;
                     @weakify(self)
                     cell.textChangeBlock = ^(NSInteger tag, id body) {
                         @strongify(self)
                         
                     };

                 }
        return cell;


    }else {
        if (indexPath.row == 0) {
             UITableViewCell *lastCell = [tableView dequeueReusableCellWithIdentifier:@"lastCellIdentifier"];
                   [lastCell.contentView addSubview:self.deleteLbl];
                   [self.deleteLbl mas_updateConstraints:^(MASConstraintMaker *make) {
                       make.left.mas_equalTo(lastCell.contentView).mas_offset(kMarginOffsetX);
                       make.centerY.mas_equalTo(lastCell.contentView.mas_centerY);
                   }];
            return lastCell;
        }
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}


 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     return  [InputTempletTwelveTableViewCell heightForCell];
     
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return   3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 6;
    }else if (section == 1) {
        return 2;
    }else {
        return 1;
    }
    return 0;
}


- (void)textFieldDidChange:(UITextField *)textField {
   CGFloat cellHeight = [self heightForCellWithText:textField.text];

}

- (CGFloat)heightForCellWithText:(NSString *)text{
    if (IsEmptyStr(text)) {
        return 0.0;
    }
    CGFloat maxSize = SCREEN_WIDTH -  2*kMarginOffsetX ;
    UIFont *font = PingFangZhongChangGuiForFont(14);
    CGSize size = [PlatformTools sizeWithString:text andFount:font andMaxSize:CGSizeMake(maxSize, MAXFLOAT)];
    return size.height + 53;
}

 



- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [UIConfigure tableViewFromFactory];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 250;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        [_tableView registerClass:[InputTempletTwelveTableViewCell class] forCellReuseIdentifier:@"InputTempletTwelveTableViewCellIdentifier"];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"lastCellIdentifier"];

    }
    return _tableView;
}

MACRO_UILabelWithPFCGFont(deleteLbl,@"删除此用户",kRedColor,18)
MACRO_UILabelWithPFCGFont(titleLblFirst,@"基本信息",kGrayColor,15)
MACRO_UILabelWithPFCGFont(titleLblSecond,@"司机信息",kGrayColor,15)




@end
